/*
 * Copyright (c) 2017-present Ilhasoft.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package br.com.ilhasoft.support.validation.util;

import ohos.agp.components.Component;

/**
 * 返回错误信息
 * Created by john-mac on 3/24/17.
 */
public class ErrorMessageHelper {
    /**
     * 返回错误信息
     *
     * @param view view
     * @param errorMessage message
     * @param defaultMessage defaultMessage
     * @return Message Message
     */
    public static String getStringOrDefault(Component view, String errorMessage,
        String defaultMessage) {
        return errorMessage != null ? errorMessage : defaultMessage;
    }

    /**
     * 返回错误信息
     *
     * @param view view
     * @param errorMessage message
     * @param defaultMessage defaultMessage
     * @param value value
     * @return Message Message
     */
    public static String getStringOrDefault(Component view, String errorMessage,
        int defaultMessage, int value) {
        return errorMessage != null ? errorMessage : view.getContext().getString(defaultMessage, value);
    }

    /**
     * 返回错误信息
     *
     * @param view view
     * @param errorMessage message
     * @param defaultMessage defaultMessage
     * @return Message Message
     */
    public static String getStringOrDefault(Component view, CharSequence errorMessage,
        int defaultMessage) {
        return errorMessage != null ? errorMessage.toString() : view.getContext().getString(defaultMessage);
    }

    /**
     * 返回错误信息
     *
     * @param view view
     * @param errorMessage message
     * @param defaultMessage defaultMessage
     * @param value value
     * @return Message Message
     */
    public static String getStringOrDefault(Component view, CharSequence errorMessage,
        String defaultMessage, int value) {
        return errorMessage != null ? errorMessage.toString() : defaultMessage;
    }
}
